#! /bin/bash
### BEGIN INIT INFO
# Provides:          vbox
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

VMUSER=zhengkai
VMNAME="Shiva"

case "$1" in
  start)
    echo "Starting VirtualBox VM..."
    sudo -H -b -u $VMUSER /usr/bin/VBoxHeadless -s "$VMNAME"
    ;;
  stop)
    echo "Saving state of Virtualbox VM..."
    sudo -H -u  $VMUSER /usr/bin/VBoxManage controlvm "$VMNAME" acpipowerbutton
    ;;
  *)
    echo "Usage: /etc/init.d/vbox {start|stop}"
    exit 1
    ;;
esac

exit 0
